package hanelsoft.vn.dictionaylearn.control.service;

import java.util.Calendar;

import android.app.AlarmManager;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.IBinder;
import android.util.Log;

public class WidgetStartService extends Service{
	String TAG = "[WidgetStartService]";
	SharedPreferences shareWidget;
	Intent mIntent;
	PendingIntent pendingIntent;
	AlarmManager alarmManager;
	@Override
	public IBinder onBind(Intent intent) {
		// TODO Auto-generated method stub
		return null;
	}
	@Override
	public void onCreate() {
		super.onCreate();
		Log.i(TAG, "Start onCreate");
		shareWidget = getSharedPreferences("ShareWidget", 0);
		mIntent = new Intent(this, WidgetUpdateService.class);
		//mIntent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
		startService(mIntent);
		Log.i(TAG, "Start pendingIntentAlarm");
		pendingIntent = PendingIntent.getService(this, 0, mIntent, 0);
		AlarmManager alarmManager = (AlarmManager)getSystemService(ALARM_SERVICE);
		Calendar calendar = Calendar.getInstance();
		calendar.setTimeInMillis(System.currentTimeMillis());
		int time = 10;
		time = shareWidget.getInt("Setting_Time_Wait_Widget", 0);
		calendar.add(Calendar.SECOND, time);
		alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(),time * 1000, pendingIntent);
	}
}
